/*!
 * \file t__frtrim.c
 *
 * All Rights Reserved Copyright (C) 2014 broada,Co.,Ltd.\n
 *
 * \version 3.0
 * \author geyh
 * \date 2016/03/31
 *
 */
#include <CUnit/Basic.h>
#include <stdlib.h>

#include "frcomm.h"
#include "frmem.h"
#include "frconfig.h"
#include "conntrack.h"
#include "frct_comm.h"

#include "apmtest_comm.h"

extern char *__frtrim(char *src);

static int __suite_init(void)
{

    return 0;
}

static int __suite_cleanup(void)
{

    return 0;
}

static void __case1(void)
{
    char *p_src = NULL;

    p_src = __frtrim(p_src);

    CU_ASSERT_PTR_NULL(p_src);

}

static void __case2(void)
{
    char *p_src = (char *)frstrdup("\0");

    p_src = __frtrim(p_src);

    CU_ASSERT_STRING_EQUAL(p_src,"\0");

    frfree(p_src);

}

static void __case3(void)
{
    char *p_src = NULL;
    char *p_tmp = NULL;

    p_src = (char *)frstrdup("  time  ");
    p_tmp = p_src;
    p_src = __frtrim(p_src);

    CU_ASSERT_STRING_EQUAL(p_src,"time");

    frfree(p_tmp);
}

static void __case4(void)
{
    char *p_src = NULL;
    char *p_tmp = NULL;

    p_src = (char *)frstrdup("   time    ");
    p_tmp = p_src;
    p_src = __frtrim(p_src);

    CU_ASSERT_STRING_EQUAL(p_src,"time");

    frfree(p_tmp);

}

static void __case5(void)
{
    char *p_src = NULL;
    char *p_tmp = NULL;

    p_src = (char *)frstrdup("  time");
    p_tmp = p_src;
    p_src = __frtrim(p_src);

    CU_ASSERT_STRING_EQUAL(p_src,"time");

    frfree(p_tmp);
}

static void __case6(void)
{
    char *p_src = NULL;
    char *p_tmp = NULL;

    p_src = (char *)frstrdup("   time");
    p_tmp = p_src;
    p_src = __frtrim(p_src);

    CU_ASSERT_STRING_EQUAL(p_src,"time");

    frfree(p_tmp);
}

static void __case7(void)
{
    char *p_src = NULL;
    char *p_tmp = NULL;

    p_src = (char *)frstrdup("time  ");
    p_tmp = p_src;
    p_src = __frtrim(p_src);

    CU_ASSERT_STRING_EQUAL(p_src,"time");

    frfree(p_tmp);
}

static void __case8(void)
{
    char *p_src = NULL;
    char *p_tmp = NULL;

    p_src = (char *)frstrdup("time   ");
    p_tmp = p_src;
    p_src = __frtrim(p_src);

    CU_ASSERT_STRING_EQUAL(p_src,"time");

    frfree(p_tmp);
}

int add_suite___frtrim(void)
{
    CU_pSuite pSuite = NULL;

    if ((pSuite = CU_add_suite("frcomm __frtrim()", __suite_init, __suite_cleanup)) == NULL)
        return FR_FAIL;

    CU_add_test(pSuite, "case1", __case1);
    CU_add_test(pSuite, "case2", __case2);
    CU_add_test(pSuite, "case3", __case3);
    CU_add_test(pSuite, "case4", __case4);
    CU_add_test(pSuite, "case5", __case5);
    CU_add_test(pSuite, "case6", __case6);
    CU_add_test(pSuite, "case7", __case7);
    CU_add_test(pSuite, "case8", __case8);

    return FR_SUCC;
}
